//牛客 WY22 Fibonacci数列
#include <iostream>
#include<cmath>
using namespace std;

int main() 
{
   int n;
   cin>>n;

   int a=0,b=1,tmp=0;
   while(b<n)
   {
    tmp=b;
    b=a+b;
    a=tmp;
   }

   int step = min(abs(n-a),abs(n-b));
   cout<<step<<endl;

   return 0;
}
